package com.dkm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dkm.entity.SongList;
import com.dkm.service.SongListService;
import com.dkm.util.LayuiJsonUilt;
import com.dkm.util.MusicUtil;

@RestController
@RequestMapping(value = "/songList")
public class SongListController {

	//注入歌曲业务层
	@Autowired
	private SongListService songListService;
	
	@GetMapping
	public LayuiJsonUilt<SongList> getAllSongList(String user_id,LayuiJsonUilt<SongList> lj) {
		Map<String, Object> map=new HashMap<String, Object>();
		
		if(user_id!=null&&user_id!="") {
			map.put("user_id", user_id);
		}
		//创建jpa的分页对象
		Pageable pageable=PageRequest.of(lj.getPage(), lj.getLimit());
		//获取page对象
		Page<SongList> p=songListService.getAllSongList(map, pageable);
		
		//设置数据和数据长度
		lj.setData(p.getContent());
		lj.setCount(p.getTotalElements());
		
		return lj;
	}
	
	@GetMapping("/getSongsByUser_id")
	public List<MusicUtil> getSongsByUser_id(String user_id) {
		
		return songListService.getSongsByUser_id(user_id);
	}
}
